home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / kernel / fs / fsAttributes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-19  |  6.3 KB  |  192 lines

  1. /*
  2.  * fsAttributes.c --
  3.  *
  4.  *    This has procedures for operations done on file attributes.
  5.  *    The general strategy when getting attributes is to make one call to
  6.  *    the name server to get an initial version of the attributes, and
  7.  *    then make another call to the I/O server to update things like
  8.  *    the access time and modify time.  There are two ways to get to
  9.  *    the name server, either via a pathname or an open file.  The
  10.  *    I/O server is always contacted using a fileID.
  11.  *
  12.  * Copyright 1987 Regents of the University of California
  13.  * All rights reserved.
  14.  * Permission to use, copy, modify, and distribute this
  15.  * software and its documentation for any purpose and without
  16.  * fee is hereby granted, provided that the above copyright
  17.  * notice appear in all copies.  The University of California
  18.  * makes no representations about the suitability of this
  19.  * software for any purpose.  It is provided "as is" without
  20.  * express or implied warranty.
  21.  */
  22.  
  23. #ifndef lint
  24. static char rcsid[] = "$Header: /cdrom/src/kernel/Cvsroot/kernel/fs/fsAttributes.c,v 9.4 91/09/10 18:22:19 rab Exp $ SPRITE (Berkeley)";
  25. #endif not lint
  26.  
  27.  
  28. #include <sprite.h>
  29. #include <fs.h>
  30. #include <fsutil.h>
  31. #include <fsNameOps.h>
  32. #include <fslcl.h>
  33. #include <fsconsist.h>
  34. #include <fscache.h>
  35. #include <fsdm.h>
  36. #include <fsStat.h>
  37. #include <rpc.h>
  38.  
  39. #include <stdio.h>
  40.  
  41.  
  42. /*
  43.  *----------------------------------------------------------------------
  44.  *
  45.  * Fs_GetAttrStream --
  46.  *
  47.  *    Get the attributes of an open file.  The name server for the
  48.  *    file (if any, anonymous pipes won't have one) is contacted
  49.  *    to get the initial version of the attributes.  This includes
  50.  *    ownership, permissions, and a guess as to the size.  Then
  51.  *    a stream-specific call is made to update the attributes
  52.  *    from info at the I/O server.  For example, there may be
  53.  *    more up-to-date access and modify times at the I/O server.
  54.  *
  55.  * Results:
  56.  *    An error code and the attibutes.
  57.  *
  58.  * Side effects:
  59.  *    None.
  60.  *
  61.  *----------------------------------------------------------------------
  62.  */
  63.  
  64. ReturnStatus
  65. Fs_GetAttrStream(streamPtr, attrPtr)
  66.     Fs_Stream *streamPtr;
  67.     Fs_Attributes *attrPtr;
  68. {
  69.     register ReturnStatus    status;
  70.     register Fs_HandleHeader    *hdrPtr = streamPtr->ioHandlePtr;
  71.     register Fs_NameInfo        *nameInfoPtr = streamPtr->nameInfoPtr;
  72.  
  73.     if (!Fsutil_HandleValid(hdrPtr)) {
  74.     status = FS_STALE_HANDLE;
  75.     } else {
  76.     if (nameInfoPtr == (Fs_NameInfo *)NIL) {
  77.         /*
  78.          * Anonymous pipes have no name info.
  79.          */
  80.         bzero((Address)attrPtr, sizeof(Fs_Attributes));
  81.         status = SUCCESS;
  82.     } else {
  83.         /*
  84.          * Get the initial version of the attributes from the file server
  85.          * that has the name of the file.
  86.          */
  87.         status = (*fs_AttrOpTable[nameInfoPtr->domainType].getAttr)
  88.             (&nameInfoPtr->fileID, rpc_SpriteID, attrPtr);
  89. #ifdef lint
  90.         status = FslclGetAttr(&nameInfoPtr->fileID, rpc_SpriteID,attrPtr);
  91.         status = FsrmtGetAttr(&nameInfoPtr->fileID,rpc_SpriteID,attrPtr);
  92.         status = FspdevPseudoGetAttr(&nameInfoPtr->fileID,rpc_SpriteID,attrPtr);
  93. #endif lint
  94.         if (status != SUCCESS) {
  95.         printf(
  96.             "Fs_GetAttrStream: can't get name attributes <%x> for %s\n",
  97.             status, Fsutil_GetFileName(streamPtr));
  98.         }
  99.     }
  100.     if (status == SUCCESS) {
  101.         /*
  102.          * Update the attributes by contacting the I/O server.
  103.          */
  104.         fs_Stats.cltName.getIOAttrs++;
  105.         status = (*fsio_StreamOpTable[hdrPtr->fileID.type].getIOAttr)
  106.             (&hdrPtr->fileID, rpc_SpriteID, attrPtr);
  107. #ifdef lint
  108.         status = Fsrmt_GetIOAttr(&hdrPtr->fileID, rpc_SpriteID, attrPtr);
  109.         status = FsrmtFileGetIOAttr(&hdrPtr->fileID, rpc_SpriteID, attrPtr);
  110.         status = Fsio_DeviceGetIOAttr(&hdrPtr->fileID, rpc_SpriteID, attrPtr);
  111.         status = Fsio_PipeGetIOAttr(&hdrPtr->fileID, rpc_SpriteID, attrPtr);
  112.         status = FsRmtControlGetIOAttr(&hdrPtr->fileID, rpc_SpriteID,
  113.             attrPtr);
  114.         status = FspdevControlGetIOAttr(&hdrPtr->fileID, rpc_SpriteID,
  115.             attrPtr);
  116. #endif lint
  117.     }
  118.     fs_Stats.cltName.getAttrIDs++;
  119.     }
  120.     return(status);
  121. }
  122.  
  123. /*
  124.  *----------------------------------------------------------------------
  125.  *
  126.  * Fs_SetAttrStream --
  127.  *
  128.  *    Set the attributes of an open file.  First the name server is
  129.  *    contacted to verify permissions and to update the file descriptor.
  130.  *    Then the I/O server is contacted to update any cached attributes.
  131.  *
  132.  * Results:
  133.  *    An error code.
  134.  *
  135.  * Side effects:
  136.  *    The modify and access times are set.
  137.  *    The owner and group ID are set.
  138.  *    The permission bits are set.
  139.  *     If the operation is successful, the count of setAttrs is incremented.
  140.  *
  141.  *----------------------------------------------------------------------
  142.  */
  143.  
  144. ReturnStatus
  145. Fs_SetAttrStream(streamPtr, attrPtr, idPtr, flags)
  146.     Fs_Stream *streamPtr;    /* References file to manipulate. */
  147.     Fs_Attributes *attrPtr;    /* Attributes to give to the file. */
  148.     Fs_UserIDs *idPtr;        /* Owner and groups of calling process */
  149.     int flags;            /* Specify what attributes to set. */
  150. {
  151.     register ReturnStatus    status;
  152.     register Fs_HandleHeader    *hdrPtr = streamPtr->ioHandlePtr;
  153.     register Fs_NameInfo        *nameInfoPtr = streamPtr->nameInfoPtr;
  154.  
  155.     if (!Fsutil_HandleValid(hdrPtr)) {
  156.     status = FS_STALE_HANDLE;
  157.     } else {
  158.     if (streamPtr->nameInfoPtr != (Fs_NameInfo *)NIL) {
  159.         /*
  160.          * Set the attributes at the name server.
  161.          */
  162.         status = (*fs_AttrOpTable[nameInfoPtr->domainType].setAttr)
  163.             (&nameInfoPtr->fileID, attrPtr, idPtr, flags);
  164. #ifdef lint
  165.         status = FslclSetAttr(&nameInfoPtr->fileID, attrPtr,idPtr,flags);
  166.         status = FsrmtSetAttr(&nameInfoPtr->fileID, attrPtr,idPtr,flags);
  167.         status = FspdevPseudoSetAttr(&nameInfoPtr->fileID, attrPtr,idPtr,flags);
  168. #endif lint
  169.     } else {
  170.         status = SUCCESS;
  171.     }
  172.     if (status == SUCCESS) {
  173.         /*
  174.          * Set the attributes at the I/O server.
  175.          */
  176.         fs_Stats.cltName.setIOAttrs++;
  177.         status = (*fsio_StreamOpTable[hdrPtr->fileID.type].setIOAttr)
  178.             (&hdrPtr->fileID, attrPtr, flags);
  179. #ifdef lint
  180.         status = Fsrmt_SetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  181.         status = FsrmtFileSetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  182.         status = Fsio_DeviceSetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  183.         status = Fsio_PipeSetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  184.         status = FsRmtControlSetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  185.         status = FspdevControlSetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  186. #endif lint
  187.     }
  188.     fs_Stats.cltName.setAttrIDs++;
  189.     }
  190.     return(status);
  191. }
  192.